import db from "../../db";

export default defineEventHandler(async (event) => {
  const query = getQuery(event);
  const page: number = parseInt(query.page as string, 10) || 1;
  const pageSize: number = parseInt(query.pageSize as string, 10) || 10;
  const offset = (page - 1) * pageSize;
  const limit = pageSize;
  try {
    const [rows] = await db.query(`SELECT video_id,title,cover,video_url,create_time,update_time FROM video_center ORDER BY create_time DESC LIMIT ?, ?`, [offset, limit]);
    return {
      code: 1,
      message: "成功",
      data: rows,
    };
  } catch (error) {
    console.error(error);
    return {
      code: 500,
      message: "服务器内部错误",
      data: null,
    };
  }
});
